package aos.client.robot;
import org.apache.log4j.Logger;

import aos.client.skype.SkypeClient;
import aos.server.robot.RobotControllerProxy;

public class RemoteRobotControllerProxy  implements RobotControllerProxy {
	
	Logger logger = Logger.getLogger(RemoteRobotControllerProxy.class);
	
	SkypeClient skypeClient;
	
	double xhead = -1.0;
	double yhead = -1.0;
	double xwheel = -1.0;
	double ywheel = -1.0;
	
	public RemoteRobotControllerProxy() {
		skypeClient = new SkypeClient();
		logger.info("Skype client initialized.");
	}
	
	@Override
	public void setPosition(double xhead, double yhead, double xwheel, double ywheel) {
		if (this.xhead != xhead || this.yhead != yhead || this.xwheel == xwheel || this.ywheel == ywheel) {
			this.xhead = xhead;
			this.yhead = yhead;
			this.xwheel = xwheel;
			this.ywheel = ywheel;
			updatePosition();
		}
	}
	
	private void updatePosition(){
		logger.info("Update position Head [x: " + this.xhead + "; y: " + this.yhead + "] Wheel [x: " + this.xwheel + "; y: " + this.ywheel + "]");
		skypeClient.writeData(this.xhead + "," + this.yhead + "," + this.xwheel + "," + this.ywheel);
	}

}
